<template>
  <BasicModal
    v-bind="$attrs"
    :title="props.title"
    @register="registerModal"
    width="700px"
    @ok="handleSubmit"
  >
    <PageWrapper>
      <!-- <p class="h-20" v-for="index in 20" :key="index">根据屏幕高度自适应</p> -->
      <BasicForm @register="register" :showSubmitButton="false" :showResetButton="false" />
    </PageWrapper>
  </BasicModal>
</template>
<script lang="ts" setup>
  import { onMounted, nextTick } from 'vue';
  import { BasicModal, useModal } from '@/components/Modal';
  import { PageWrapper } from '@/components/Page';
  import { BasicForm, useForm } from '@/components/Form';
  import { createDeliveryOrderAPI } from '@/api/eslogis-tps/index';

  import { addresSchemas } from './createDialog';

  const emit = defineEmits(['close']);
  const props = defineProps({
    title: {
      type: String,
      default: '',
    },
    // editData: {
    //   type: Object,
    //   default: '',
    // },
  });
  const [registerModal, { closeModal }] = useModal();
  //  setFieldsValue: setFieldsValueWarehouse,
  const [register, { validate, resetFields }] = useForm({
    layout: 'vertical',
    baseColProps: {
      span: 6,
    },
    schemas: addresSchemas,
    // showActionButtonGroup: false,
  });
  // watch(
  //   props.editData,
  //   (data) => {
  //     console.log('监听编辑数据变化', data, props.editData);
  //     // setFieldsValue(props.editData)
  //     nextTick(() => {
  //       //  setFieldsValue(props.editData.value)
  //     });
  //   },
  //   { deep: true },
  // );
  onMounted(() => {
    console.log('onMounted');
    nextTick(() => {
      console.log('onMountednextTick');
    });
  });

  async function handleSubmit() {
    try {
      const [values] = await Promise.all([validate()]);
      console.log('form data:', values);
      const data = {
        ...values,
      };
      createDeliveryOrderAPI(data).then((res) => {
        console.log(res);
        resetFields();
        closeModal();
        emit('reload');
      });
    } catch (error) {
      console.log(error);
    }
  }
</script>
